package com.JZ.QM.service.impl;

import com.JZ.QM.service.WealthPositionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.JZ.QM.common.utils.PageUtils;
import com.JZ.QM.common.utils.Query;

import com.JZ.QM.common.dao.WealthPositionDao;
import com.JZ.QM.common.entity.WealthPositionEntity;

import javax.annotation.Resource;


@Service
public class WealthPositionServiceImpl extends ServiceImpl<WealthPositionDao, WealthPositionEntity> implements WealthPositionService {

    @Resource
    WealthPositionDao wealthPositionDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) throws Exception {
        IPage<WealthPositionEntity> page = this.page(
                new Query<WealthPositionEntity>().getPage(params),
                new QueryWrapper<WealthPositionEntity>()
        );

        return new PageUtils(page);
    }


    /**
     * 通过财富账号获取持仓列表
     * @param wealthAccountId
     * @return
     */
    @Override
    public ArrayList<WealthPositionEntity> getListByWealthAccountId(Long wealthAccountId) {
        //构造条件查询器
        QueryWrapper<WealthPositionEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wealth_account_id",wealthAccountId);
        //结果集
        ArrayList<WealthPositionEntity> wealthPositionEntityArrayList = new ArrayList<>();

        wealthPositionEntityArrayList = (ArrayList<WealthPositionEntity>) wealthPositionDao.selectList(queryWrapper);

        return wealthPositionEntityArrayList;
    }

    @Override
    public WealthPositionEntity getPosition(Long userId, Long WealthAccountId, Long proId) {
        //持仓实体
        WealthPositionEntity wealthPositionEntity = new WealthPositionEntity();
        //条件查询器
        QueryWrapper<WealthPositionEntity> queryWrapper =  new QueryWrapper<>();
        queryWrapper.eq("pro_id",proId)
                    .eq("wealth_account_id",WealthAccountId)
                    .eq("user_id",userId);

        wealthPositionEntity = wealthPositionDao.selectOne(queryWrapper);

        return wealthPositionEntity;
    }

}